import axios from '../utils/axios'

// Excel导入相关API
export const excelApi = {
  // 导入身份信息Excel
  importIdentityExcel(file, userId, formData = {}) {
    const form = new FormData()
    form.append('file', file)
    if (userId) {
      form.append('userId', userId)
    }
    // 添加表单数据
    if (formData.reportDate) {
      form.append('reportDate', formData.reportDate)
    }
    
    return axios.post('/excel/import/identity', form, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 导入收入信息Excel
  importIncomeExcel(file, userId, formData = {}) {
    const form = new FormData()
    form.append('file', file)
    if (userId) {
      form.append('userId', userId)
    }
    // 添加表单数据
    if (formData.quarter) {
      form.append('quarter', formData.quarter)
    }
    if (formData.startTime) {
      form.append('startTime', formData.startTime)
    }
    if (formData.endTime) {
      form.append('endTime', formData.endTime)
    }
    if (formData.reportDate) {
      form.append('reportDate', formData.reportDate)
    }
    
    return axios.post('/excel/import/income', form, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 导入平台信息Excel
  importPlatformExcel(file, userId, formData = {}) {
    const form = new FormData()
    form.append('file', file)
    if (userId) {
      form.append('userId', userId)
    }
    // 添加表单数据
    if (formData.reportDate) {
      form.append('reportDate', formData.reportDate)
    }
    
    return axios.post('/excel/import/platform', form, {
      headers: {
        'Content-Type': 'multipart/form-data'
      }
    })
  },

  // 下载Excel模板
  downloadTemplate(type) {
    return axios.get(`/excel/template/${type}`, {
      responseType: 'blob'
    })
  },

  // 导出Excel数据
  exportData(type, params = {}) {
    return axios.get(`/excel/export/${type}`, {
      params,
      responseType: 'blob'
    })
  },

  // 获取导入历史记录
  getImportHistory(params = {}) {
    return axios.get('/excel/import/history', { params })
  },

  // 删除导入记录
  deleteImportRecord(id) {
    return axios.delete(`/excel/import/record/${id}`)
  }
}
